What is Pandas

Is is an open-source Python library used for data manipulation and analysis. it can analyze csv data and perform operations as mean, min, max etc.
parsing multiple file formats converting input data table into a NumPy matrix arrays.

Datastructures in Pandas

Pandas provides two types of classes for handling data: Series, Dataframes

1. Series

A one-dimensional labeled array holding data of any type such as integers, strings, Python objects etc.

Internally Examples

struct Series {
    Index index_array; // Stores ['Alice', 'Bob', 'Charlie']
    Data  values_array; // Stores [85, 92.01, "test"]
}
          

Series is composed of a data array and an index array.
They are managed as two separate, parallel arrays.

The Index Array: This is an object that handles labels, lookups, and alignment.
The Values Array: If all data is the same type (e.g., all integers),
this is a contiguous, high-performance block of
memory (like a C array). When you mix types, it becomes an array of references to Python objects.

import pandas as pd

s = pd.Series()
print(series,'\n')
Series([], dtype: float64)    //Output

series = pd.Series(5)
print(series,'\n')
0    5            //Output
dtype: int64 

scores = pd.Series([85, 92, 78], index=['Alice', 'Bob', 'Charlie'])
print(scores)
Alice      85     //Output
Bob        92
Charlie    78
dtype: int64

series = pd.Series([85, 92.01, "test"], index=['Alice', 'Bob', 'Charlie'])
print(series)
Alice         85    //Output
Bob        92.01
Charlie     test
dtype: object

# Setting index using Dictionary
s = pd.Series({'a':1, 'b':2, 'c':3})
print(s,'\n')
a    1            //Output
b    2
c    3
dtype: int64
          

2. Dataframes

A 2-dimensional data structure that holds data like a two-dimension array or a table with rows and columns.(Eg: csv file)

df = pd.DataFrame()         #Empty DataFrame
print(df)
Columns: []
Index: []

df = pd.DataFrame([5, 6])
print(df)
   0
0  5
1  6

data = {
    'Age': [20, 21, 19],
    'Score': [85, 92, 78]
}
df = pd.DataFrame(data, index=['Alice', 'Bob', 'Charlie'])
print (df)
         Age  Score         //Output
Alice     20     85
Bob       21     92
Charlie   19     78
                                
df = pd.DataFrame({'c1': [1, 2], 'c2': [3, 4]},               //taking dictionary as argument
                  index=['r1', 'r2'])
print(df)                                   #    c1  c2
                                            #r1   1   3
                                            #r2   2   4

// Append additional rows
df = pd.DataFrame([[5, 6], [1.2, 3]])
print(df)                                     #     0  1
                                              # 0  5.0  6
                                              # 1  1.2  3 
r = pd.Series([0, 0], name='r3')

df = df.append(r)
print('{}\n'.format(r))                       #      0  1
                                              # 0   5.0  6
                                              # 1   1.2  3
                                              # r3  0.0  0

// Dropping rows, coloumns
df = pd.DataFrame({'c1': [1, 2], 'c2': [3, 4], 'c3': [5, 6]}, index=['r1', 'r2'])
print(df)                                   #     c1  c2  c3
                                            # r1   1   3   5
                                            # r2   2   4   6
df = df.drop(labels='r1')
print(df)                                   #     c1  c2  c3
                                            # r2   2   4   6